package cn.com.haopy.dataes.db.service.main.impl;

import cn.com.haopy.dataes.db.entity.main.HDNotice;
import cn.com.haopy.dataes.db.mapper.main.HDNoticeMapper;
import cn.com.haopy.dataes.db.service.main.HDNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HDNoticeServiceImpl extends ServiceImpl<HDNoticeMapper, HDNotice> implements HDNoticeService {
    @Override
    public Page<HDNotice> querySelective(String title, String content, Integer pageNo, Integer size, String sort, String order) {
        QueryWrapper<HDNotice> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(title)) {
            queryWrapper.lambda().like(HDNotice::getTitle, "%" + title + "%");
        }

        if (StringUtils.hasText(content)) {
            queryWrapper.lambda().like(HDNotice::getContent, "%" + content + "%");
        }

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }

        Page<HDNotice> page = new Page<>(pageNo, size);
        return super.page(page, queryWrapper);
    }
}
